package com.pj.wisdomlogistics.ui.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.pj.wisdomlogistics.MyApplication;
import com.pj.wisdomlogistics.R;
import com.pj.wisdomlogistics.mvp.contract.RetPwdContract;
import com.pj.wisdomlogistics.mvp.frame.MvpActivity;
import com.pj.wisdomlogistics.mvp.frame.base.BaseView;
import com.pj.wisdomlogistics.mvp.presenter.RetPwdPresenter;
import com.pj.wisdomlogistics.other.EventCenter;
import com.pj.wisdomlogistics.utils.ActivityManagerUtil;
import com.pj.wisdomlogistics.utils.CustomToast;

import butterknife.BindView;
import butterknife.OnClick;

public class RetPwdActivity extends MvpActivity<RetPwdPresenter> implements RetPwdContract.View {
    @BindView(R.id.et_old)
    EditText mEtOld;
    @BindView(R.id.et_new)
    EditText mEtNew;

    @Override
    public void onError(String errorMsg) {
        dismissProgressDialog();
        CustomToast.showToast(this , errorMsg , 1000);
    }

    @Override
    public void onSuccess() {
        dismissProgressDialog();
        CustomToast.showToast(this , "修改成功" , 1000);
    }

    @Override
    protected BaseView getBaseView() {
        return this;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {

    }

    @Override
    public int getContentView() {
        return R.layout.activity_ret_pwd;
    }

    @Override
    public boolean isApplyEventBus() {
        return false;
    }

    @Override
    public boolean isApplyButterKnife() {
        return true;
    }

    @Override
    public void onEventCome(EventCenter eventCenter) {

    }


    @OnClick({R.id.iv_back, R.id.bt_sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                ActivityManagerUtil.create().finishActivity();
                break;
            case R.id.bt_sure:
                String oldPwd = mEtOld.getText().toString().trim();
                String newPwd = mEtNew.getText().toString().trim();

                if(TextUtils.isEmpty(oldPwd) || TextUtils.isEmpty(newPwd)){
                    CustomToast.showToast(this , "请将资料填写完整" , 1000);
                    return;
                }

                if(TextUtils.equals(oldPwd , newPwd)){
                    CustomToast.showToast(this , "新密码与原密码相同" , 1000);
                    return;
                }

                mPresenter.mofifyPassword(MyApplication.userID , newPwd , oldPwd);
                showProgressDialog();
                break;
        }
    }
}
